
#ifndef __FLASH_H
#define __FLASH_H


#ifdef __cplusplus
 extern "C" {
#endif

#include "define.h"
//W25X系列/Q系列芯片列表
//W25Q80  ID  0XEF13
//W25Q16  ID  0XEF14
//W25Q32  ID  0XEF15
//W25Q64  ID  0XEF16
//W25Q128 ID  0XEF17
#define W25Q80 	0XEF13
#define W25Q16 	0XEF14
#define W25Q32 	0XEF15
#define W25Q64 	0XEF16
#define W25Q128	0XEF17

#define NM25Q80 	0X5213
#define NM25Q16 	0X5214
#define NM25Q32 	0X5215
#define NM25Q64 	0X5216
#define NM25Q128	0X5217
#define NM25Q256 	0X5218


#define AUD_SIZE    1024*1024       //语音用1M的空间保存
#define ALL_SIZE    16*1024*1024    //全片大小16M byte

extern uint16_t W25QXX_TYPE;								//定义W25QXX芯片型号
uint16_t W25QXX_TYPE;										//W25Q128;	//默认是W25Q128
#define	W25QXX_CS_1 		GPIO2->ODR |=  (1UL<<7); 		//W25QXX的片选信号
#define	W25QXX_CS_0 		GPIO2->ODR &= ~(1UL<<7); 		//W25QXX的片选信号
////////////////////////////////////////////////////////////////////////////

//指令表
#define W25X_WriteEnable		0x06
#define W25X_WriteDisable		0x04
#define W25X_ReadStatusReg		0x05
#define W25X_WriteStatusReg		0x01
#define W25X_ReadData			0x03
#define W25X_FastReadData		0x0B
#define W25X_FastReadDual		0x3B
#define W25X_PageProgram		0x02
#define W25X_BlockErase			0xD8
#define W25X_SectorErase		0x20
#define W25X_ChipErase			0xC7
#define W25X_PowerDown			0xB9
#define W25X_ReleasePowerDown	0xAB
#define W25X_DeviceID			0xAB
#define W25X_ManufactDeviceID	0x90
#define W25X_JedecDeviceID		0x9F

void W25QXX_Init(void);
uint16_t  W25QXX_ReadID(void);  	    		//读取FLASH ID
uint8_t	  W25QXX_ReadSR(void);        			//读取状态寄存器
void W25QXX_Write_SR(uint8_t sr);  				//写状态寄存器
void W25QXX_Write_Enable(void);  				//写使能
void W25QXX_Write_Disable(void);				//写保护
void W25QXX_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
void W25QXX_Read(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead);   //读取flash
void W25QXX_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);//写入flash
void W25QXX_Erase_Chip(void);    	  			//整片擦除
void W25QXX_Erase_Sector(uint32_t Dst_Addr);	//扇区擦除
void W25QXX_Wait_Busy(void);           			//等待空闲
void W25QXX_PowerDown(void);        			//进入掉电模式
void W25QXX_WAKEUP(void);						//唤醒


//---------------------------  UI entry ------------------------------------------//
#define   SECTOR_SIZE  			4096     //一个setor 4096
#define   USER_SECTOR_NUM  		8   	 //一个用户用5个sector保存
#define   USER_MAX_NUM  		400 	 //最多保存多少个用户   (用户数 < 16M/USER_SECTOR_NUM/4096)
#define   AUD_SPK_ENABLE  		1

uint8_t   measuring_poweroff_flag;  	 //测量过程中如果关机measuring_poweroff_flag = 1；
uint16_t  BP_cur_adcData;    		 	 //减去零点的AD值
uint16_t  user_cur_num;                  //flash存储的用户的数量
uint32_t  w25qxx_AddNum;        		 //写入w25qxx地址的索引
uint32_t  read_max_addr;
uint32_t  w25qxx_cur_Addr;

uint8_t  Send_user_w25qxx_data(uint32_t user_num);
uint16_t Read_W25QXX_num(void);
void 	 w25qxxProgram(void);
void 	 User_W25QXX_WriteByte(uint16_t user_num,uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);


#endif



/************************ (C) COPYRIGHT SDIC Microelectronics *****END OF FILE****/












